<?php
/**
 * TomatoCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version 	$Id: server.phtml 4011 2010-07-26 01:45:38Z huuphuoc $
 * @since		2.0.6
 */
?>
<?php
$this->headTitle($this->translator('config_server_page_title'));
$this->headLink()
        ->appendStylesheet($this->APP_STATIC_SERVER . '/skins/admin/default/css/form.css');
?>
<div id="r-heading">
    <img src="<?php echo $this->APP_STATIC_SERVER . '/skins/admin/default/images/mail-48x48.png'; ?>" alt=""/>
    <span><?php echo $this->translator('config_server_breadcrumb'); ?></span>
</div>

<?php
$message = $this->flashMessenger();
if ($message) {
    ?>
    <div id="message"><?php echo $message; ?></div>
<?php } ?>

<form action="<?php echo $this->url(array(), 'mail_config_server'); ?>" method="post" enctype="multipart/form-data">
    <div class="f-guide"><?php echo $this->translator('config_server_guide'); ?></div>

    <div class="row">

        <label><?php echo $this->translator('config_mail_protocol'); ?>:</label>
        <select name="protocol" id="protocol" style="width: 200px">
            <option value="mail"<?php if ($this->protocol == 'mail') : ?> selected="selected"<?php endif; ?>><?php echo $this->translator('config_use_php_mail'); ?></option>
            <option value="smtp"<?php if ($this->protocol == 'smtp') : ?> selected="selected"<?php endif; ?>><?php echo $this->translator('config_use_smtp'); ?></option>
        </select>
    </div>

    <div class="clearfix" id="smtpContainer" style="display: <?php if ($this->protocol == 'smtp') : ?>block<?php else : ?>none<?php endif; ?>">

        <div class="clearfix row">
            <label><?php echo $this->translator('config_smtp_host'); ?>:</label>
            <input type="text" name="host" style="width: 200px"<?php if ($this->host != null) : ?> value="<?php echo $this->host; ?>"<?php endif; ?> />
        </div>



        <div class="clearfix row">
            <label><?php echo $this->translator('config_smtp_port'); ?>:</label>
            <input type="text" name="port" style="width: 50px"<?php if ($this->port != null) : ?> value="<?php echo $this->port; ?>"<?php endif; ?> />
        </div>



        <div class="clearfix row">
            <label>&nbsp;</label>
            <div>
                <input type="checkbox" name="authentication" id="authentication" value="true"<?php if ($this->username != null) : ?> checked="checked"<?php endif; ?> /> <?php echo $this->translator('config_smtp_authentication'); ?>
            </div>
        </div>



        <div id="authenticationContainer" style="display: <?php if ($this->username == null) : ?>none<?php else : ?>block<?php endif; ?>">
            <div class="clearfix row">
                <label><?php echo $this->translator('config_smtp_username'); ?>:</label>
                <input type="text" name="username" style="width: 200px"<?php if ($this->username != null) : ?> value="<?php echo $this->username; ?>"<?php endif; ?> />
            </div>



            <div class="clearfix row">
                <label><?php echo $this->translator('config_smtp_password'); ?>:</label>
                <input type="password" name="password" style="width: 200px"<?php if ($this->password != null) : ?> value="<?php echo $this->password; ?>"<?php endif; ?> />
            </div>


        </div>

        <div class="clearfix row">
            <label><?php echo $this->translator('config_smtp_security'); ?>:</label>
            <select name="security" style="width: 100px">
                <option value=""<?php if ($this->security == null) : ?> selected="selected"<?php endif; ?>><?php echo $this->translator('config_smtp_not_security'); ?></option>
                <option value="tls"<?php if ($this->security == 'tls') : ?> selected="selected"<?php endif; ?>><?php echo $this->translator('config_smtp_tls'); ?></option>
                <option value="ssl"<?php if ($this->security == 'ssl') : ?> selected="selected"<?php endif; ?>><?php echo $this->translator('config_smtp_ssl'); ?></option>
            </select>
        </div>
    </div>



    <div class="clearfix row">
        <label>&nbsp;</label>
        <button type="submit"><span><?php echo $this->translator('config_server_save_button'); ?></span></button>
    </div>
</div>
</div>
</form>

<script type="text/javascript">
    $(document).ready(function() {
        $('#protocol').change(function() {
            if ($(this).val() == 'smtp') {
                $('#smtpContainer').show();
            } else {
                $('#smtpContainer').hide();
            }
        });

        $('#authentication').click(function() {
            if ($(this).is(':checked')) {
                $('#authenticationContainer').show();
            } else {
                $('#authenticationContainer').hide();
            }
        });
    });
</script>
